package ooday04;

public class PolymorphicDemo {
    public static void main(String[] args) {
        /*
        Dog o1=new Dog("阿黄",1,"白色");

        Animal o2= new Dog("阿绿",2,"黄");

        Swim o3=new Dog("阿白",4,"绿");

         */
        /*
        Master master = new Master();
        Animal dog =new  Dog("旺财",5,"白");
        Animal fish = new Fish("坤坤",2,"金");
        Animal chilk = new Chick("小二",3,"银");

        master.feed(fish);//Animal =fish.eat()
        master.feed(dog);
        master.feed(chilk);
         */
        /*
        Animal o = new Dog("小狗",12,"白");
        Dog a = (Dog) o;
        Swim b = (Swim) o;
        //Fish c =(Fish) o;
        System.out.println(o instanceof Dog);
        System.out.println(o instanceof Swim);
        System.out.println(o instanceof  Fish);

        if(o instanceof Fish){
            Fish f=(Fish)o;
        }
         */
        Animal[] animals = new  Animal[5];
        animals[0] = new Dog("小黄",1,"黄");
        animals[1] = new Dog("小白",2,"白");
        animals[2] = new Fish("小金",3,"金");
        animals[3] = new Fish("小银",4,"银");
        animals[4] = new Chick("坤坤",5,"黑白");

        for(int i= 0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i]instanceof Dog){
                Dog dog=(Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i]instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i]instanceof Swim){
                Swim swim1 =(Swim) animals[i];
                swim1.swin();
            }
        }





    }
}
